package com.majie.aware;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

//BeanFactoryAware，可以获取到BeanFactory。
//BeanNameAware，可以获取到bean的名称。
@Component
public class MyApplicationContext implements ApplicationContextAware, BeanFactoryAware, BeanNameAware {
	ApplicationContext applicationContext;

	public String getBeanName( ) {
		return beanName;
	}

	public BeanFactory getBeanFactory( ) {
		return beanFactory;
	}

	String beanName;
	BeanFactory beanFactory;

	@Override
	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
		this.applicationContext = applicationContext;
	}

	public ApplicationContext getApplicationContext( ) {
		return applicationContext;
	}

	@Override
	public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
		this.beanFactory = beanFactory;
	}

	@Override
	public void setBeanName(String name) {
		this.beanName = name;
	}
}

